 
#include "mesh.h"
 
 
//-------------------------------------------------------------------------
Node* 
Mesh::createNode( double _x, double _y )
{
  // verifies if a node with the same coordinate already exists
  int nNodes = m_nodes.size();
  for( int i=0; i<nNodes; i++ )
  {
    if( m_nodes[i]->hasCoordinates( _x, _y ) )
    {
      return m_nodes[i];
    }
  }
  Node* node = new Node( nNodes+1, _x, _y );
  m_nodes.push_back( node );
  return node;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
Element*
Mesh::createElement( vector<int> _connect )
{
  int nElems = m_elems.size();
  Element* elem = new Element( nElems+1, _connect );
  m_elems.push_back( elem );
  return elem;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
void
Mesh::addRegion( Region* _region )
{
  m_regions.push_back( _region );
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
int
Mesh::getNodeId( double _x, double _y )
{
  return 1;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
map<int,vector<double> >
Mesh::getNodes()
{
  map<int,vector<double> > nodes;
  for( int i=0; i<m_nodes.size(); i++)
  {
    nodes[m_nodes[i]->getId()].push_back( m_nodes[i]->getX() );
    nodes[m_nodes[i]->getId()].push_back( m_nodes[i]->getY() );
  }
  return nodes;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
map<int,vector<int> >
Mesh::getElems()
{
  map<int,vector<int> > elems;
  for( int i=0; i<m_elems.size(); i++)
  {
    elems[m_elems[i]->getId()] = m_elems[i]->getConnectivity();
  }
  return elems;
}
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
vector<Region*>
Mesh::getRegions()
{
  return m_regions;
}
//-------------------------------------------------------------------------



